#!/bin/sh
#
# Usage:
#   ./4-tools.sh <function name>

. $PWD/util.sh

# NOTE: Tcl is only needed for tests.  I can make packages, but don't include
# them when building say R or Python.
#
# Also note: book doesn't instruct you to make a clean build dir.  Would that
# work?

do_tcl() {
  maybe_untar_cd tcl8.6.0-src .tar.gz
  # The last cd will fail because the tarball is named funny.
  cd tcl8.6.0

  set -o errexit

  sed -i s/500/5000/ generic/regc_nfa.c

  cd unix
  ./configure --prefix=/tools

  make
  make install

  # Make the installed library writable so debugging symbols can be removed later:
  chmod -v u+w /tools/lib/libtcl8.6.so

  make install-private-headers

  ln -sv tclsh8.6 /tools/bin/tclsh
}

do_expect() {
  maybe_untar_cd expect5.45 .tar.gz
  set -o errexit
  cp -v configure configure.orig
  sed 's:/usr/local/bin:/bin:' configure.orig > configure

  ./configure --prefix=/tools --with-tcl=/tools/lib \
      --with-tclinclude=/tools/include

  make
  make SCRIPTS="" install
}

do_dejagnu() {
  maybe_untar_cd dejagnu-1.5.1 .tar.gz
  set -o errexit
  ./configure --prefix=/tools
  make install
}

do_check() {
  maybe_untar_cd check-0.9.10 .tar.gz
  set -o errexit
  ./configure --prefix=/tools
  make install
}

"$@"
